package diwuzhou;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class PersonSortable2{
	private String name;
	private int age;
	public PersonSortable2(String name,int age){
		this.name = name;
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	@Override
	public String toString() {
		return this.name+"-"+this.age;
	}
	
}
class NameComparator implements Comparator<PersonSortable2>{
	
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		if (o1 == o2) return 0;
		return o1.getName().compareTo(o2.getName());
	}	
}

class AgeComparator implements Comparator<PersonSortable2>{

	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		if (o1 == o2) return 0;
		if (o1.getAge() > o2.getAge()) return 1;
		if (o1.getAge() < o2.getAge()) return -1;
		return 0;
	}
}
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		int n = sc.nextInt();
		PersonSortable2[] test=new PersonSortable2[n];
		for (int i = 0; i < n; i++) {
			test[i] = new PersonSortable2(sc.next(), sc.nextInt());
		}
		System.out.println("NameComparator:sort");
		Arrays.sort(test,new NameComparator());
		for (PersonSortable2 personSortable1 : test) {
			System.out.println(personSortable1);
		}
		System.out.println("AgeComparator:sort");
		Arrays.sort(test,new AgeComparator());
		for (PersonSortable2 personSortable2 : test) {
			System.out.println(personSortable2);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
		sc.close();

	}

}
